require 'open-uri'

#YAML::load(YAML::dump( hash ))
class Song
  attr_accessor :rm, :ram, :caption, :title, :mp3
  LOG_FILE = ".\\rm\\log.txt"
  def initialize(options = {})
    options.each do |attr,value|
      self.send "#{attr}=", value
    end
  end
  
  def file_name
    ".\\rm\\#{URI.encode(@caption)}.rm"
  end
  def save
    open(file_name,"wb").write(open(@rm).read)  
    File.open(LOG_FILE,File::RDWR|File::CREAT|File::APPEND).write("#{file_name}\n")        
  end
  
  def set_rm_ram(link)
    @rm = link.rm if link.valid_rm?
    @ram = link.ram if link.valid_ram?
    @mp3 = link.mp3 if @rm and @ram
#    save if @rm and @ram
  end
end
